//
//  JCBaseTableViewController.swift
//  swiftWeibo
//
//  Created by mac on 15/12/15.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit


class JCBaseTableViewController: UITableViewController,JCVistorViewDelegate {
    
    
    
    var userlogin: Bool = JCUserAccount.userLogin
    
    override func loadView() {
        userlogin ? super.loadView() : setupVistorView()
    }
    
    
    // MARK : onClickRegister
    func onClickRegister(){
    
    }
    func onClickLogin(){
        
        let oauthVc = JCOauthController()
        let nav = JCBaseNavController(rootViewController:oauthVc)
        presentViewController(nav, animated: true, completion: nil)
        
        
    }
    func setupVistorView(){
        
        view = vistorView
        
        let registerBtn = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "onClickRegister")
        
                let loginBtn = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "onClickLogin")
        
        navigationItem.leftBarButtonItem = registerBtn
        navigationItem.rightBarButtonItem = loginBtn
        
        if self is JCHomeViewController{
            
            vistorView.startRotationAnimation()
            
//            animationStart(self)
            
            // 监听应用退到后台
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
            
            // 监听应用进入前台
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBecomeActive", name: UIApplicationDidBecomeActiveNotification, object: nil)
        }
        else if self is JCMessageViewController{
            
            vistorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }
        else if self is JCProfileViewController{
            vistorView.setupVisitorInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        else if self is JCDiscoveryViewController{
            vistorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
            
        }
        
    }
    
    // MARK: - 监听方法
    /// 应用进入后台
    func didEnterBackground() {
        vistorView.pauseAnimation()
    }
    //
    /// 应用进入前台
    func didBecomeActive() {
        vistorView.resumeAnimation()
    }
    
    // MARK: - delegate
    func onClickVisitorViewRegister() {
        
    }
    func onClickvisitorViewLogin() {
        
    }
    
    private lazy var vistorView: JCVistorView = JCVistorView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
    }
    
    
    deinit{
    
        if self is JCHomeViewController{
            NSNotificationCenter.defaultCenter().removeObserver(self)
        }
    }
    
    
    
}
